package es.udc.emarketapp.emarket.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.StringTokenizer;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

import es.udc.emarketapp.emarket.model.order.vo.OrderVO;
import es.udc.emarketapp.emarket.model.orderDetails.vo.OrderDetailsVO;
import es.udc.emarketapp.emarket.model.orderLine.dao.SQLOrderLineDAO;
import es.udc.emarketapp.emarket.model.orderLine.dao.SQLOrderLineDAOFactory;
import es.udc.emarketapp.emarket.model.orderLine.vo.OrderLineVO;
import es.udc.emarketapp.emarket.model.product.dao.SQLProductDAO;
import es.udc.emarketapp.emarket.model.product.dao.SQLProductDAOFactory;
import es.udc.emarketapp.emarket.model.product.vo.ProductVO;
import es.udc.emarketapp.emarket.model.category.vo.CategoryVO;
import es.udc.emarketapp.emarket.model.productFacade.ProductFacade;
import es.udc.emarketapp.emarket.model.productFacade.vo.ProductChunkVO;
import es.udc.emarketapp.emarket.model.purchase.dao.SQLPurchaseDAO;
import es.udc.emarketapp.emarket.model.purchase.dao.SQLPurchaseDAOFactory;
import es.udc.emarketapp.emarket.model.purchase.purchaseFacade.PurchaseFacade;
import es.udc.emarketapp.emarket.model.purchase.purchaseFacade.vo.OrderChunkVO;
import es.udc.emarketapp.emarket.model.purchase.purchaseFacade.vo.OrderLineChunkVO;
import es.udc.emarketapp.emarket.model.purchase.purchaseFacade.vo.PurchaseChunkVO;
import es.udc.emarketapp.emarket.model.purchase.vo.PurchaseVO;

import es.udc.fbellas.j2ee.util.sql.SimpleDataSource;

public final class PruebaPurchaseFacade {

	public static void main(String[] args) throws Exception {

		PurchaseFacade purchaseFacade = new PurchaseFacade();

		/*
		 * //Prueba CreatePurchase de PurchaseFacade ++++++++++++++++++
		 * 
		 * PurchaseVO purchaseVO = new
		 * PurchaseVO("martin01",null,52.23,"paypal");
		 * 
		 * purchaseFacade.createPurchase(purchaseVO);
		 */

		/*
		 * //Prueba FindPurchaserById de PurchaseFacade ++++++++++++++++++
		 * 
		 * PurchaseVO purchaseVO = purchaseFacade.findPurchaseById(new Long(7));
		 * 
		 * System.out.println(purchaseVO);
		 */

		/*
		 * //Prueba FindPurchaseByClient de PurchaseFacade
		 * +++++++++++++++++++++++
		 * 
		 * PurchaseChunkVO purchaseChunkVO; List<PurchaseVO> purchaseVOs;
		 * 
		 * int startIndex = 1; int groupCount = 2;
		 * 
		 * do { purchaseChunkVO =
		 * purchaseFacade.findPurchasesByClient("martin01", startIndex,
		 * groupCount); purchaseVOs = purchaseChunkVO.getPurchaseVOs();
		 * 
		 * for (PurchaseVO a : purchaseVOs) { System.out.println(a); }
		 * 
		 * System.out.println("--------------------------------"); startIndex +=
		 * groupCount;
		 * 
		 * } while (purchaseChunkVO.getExistMorePurchases());
		 */

		/*
		
		// Prueba FindAllPurchase de PurchaseFacade +++++++++++++++++++++++

		PurchaseChunkVO purchaseChunkVO;
		List<PurchaseVO> purchaseVOs;

		int startIndex = 1;
		int groupCount = 2;

		do {
			purchaseChunkVO = purchaseFacade.findAllPurchases(startIndex,
					groupCount);
			purchaseVOs = purchaseChunkVO.getPurchaseVOs();

			for (PurchaseVO a : purchaseVOs) {
				System.out.println(a);
			}

			System.out.println("--------------------------------");
			startIndex += groupCount;

		} while (purchaseChunkVO.getExistMorePurchases());

		*/
		
		
		/*
		 //Prueba deletePurchase de PurchaseFacade +++++++++++++++++*
		  
		  purchaseFacade.deletePurchase(new Long(4));
		*/ 
		
		
		/*
		  //Prueba ModifyPurchase de PurchaseFacade ++++++++++++++++++
		  
		  PurchaseVO purchaseVO = new PurchaseVO(new Long(6),"martin01",null,10,"paypal");
		  
		  purchaseFacade.modifyPurchase(purchaseVO);
		 */
		
		
		/*
		  //Prueba UpdatePurchaseValue de PurchaseFacade ++++++++++++++++++
		  
		  
		  purchaseFacade.updatePurchaseValue(new Long(23), 333);
		 */

		 /****************************************
		 * ORDER
		 ****************************************/
		
		
		 
		  //Prueba CreateOrder de PurchaseFacade ++++++++++++++++++
		/*
		  OrderVO orderVO = new OrderVO(new Long(3), "juancito", 88.8, 2.5,
					6.20, Calendar.getInstance(), null); 
		  
		  purchaseFacade.createOrder(orderVO);
		 */
		
		
		/* 
		  //Prueba FindOrderById de PurchaseFacade ++++++++++++++++++
		  
		  OrderVO orderVO = purchaseFacade.findOrderById(new Long(11), new Long(3));
		  
		  System.out.println(orderVO);
		 */
		
		
		/*
		  //Prueba FindOrdersBySeller de PurchaseFacade +++++++++++++++++++++++
		  
		  OrderChunkVO orderChunkVO; List<OrderVO> orderVOs;
		  
		  int startIndex = 1; int groupCount = 2;
		  
		do {
		  orderChunkVO =
		  purchaseFacade.findOrdersBySeller("juancito", startIndex,
				  groupCount); 
		  orderVOs = orderChunkVO.getOrderVOs();
		  
		  for (OrderVO a : orderVOs) { System.out.println(a); }
		  
		  System.out.println("--------------------------------"); 
		  startIndex += groupCount;
		  
		  } while (orderChunkVO.getExistMoreOrders());
		 */
	
		
		  
		  //Prueba FindOrdersByPurchase de PurchaseFacade +++++++++++++++++++++++
		  
		  OrderChunkVO orderChunkVO; List<OrderVO> orderVOs;
		  
		  int startIndex = 1; int groupCount = 2;
		  
		do {
		  orderChunkVO =
		  purchaseFacade.findOrdersByPurchase(new Long(28), 
				  startIndex, groupCount); 
		  
		  orderVOs = orderChunkVO.getOrderVOs();
		  
		  for (OrderVO a : orderVOs) { System.out.println(a.getOrderDetails().getnPedido()); }
		  
		  System.out.println("---------------------------------");
		  startIndex += groupCount;
		  
		  } while (orderChunkVO.getExistMoreOrders());
		
		
		
		/*
		  //Prueba FindOrdersBySeller de PurchaseFacade +++++++++++++++++++++++
		  
		  OrderLineChunkVO orderLineChunkVO; List<OrderLineVO> orderLineVOs;
		  
		  int startIndex = 1; int groupCount = 2;
		  
		do {
		  orderLineChunkVO =
		  purchaseFacade.findOrderLinesByOrder(new Long(1), new Long(1), 
				  startIndex, groupCount); 
		  orderLineVOs = orderLineChunkVO.getOrderLineVOs();
		  
		  for (OrderLineVO a : orderLineVOs) { System.out.println(a); }
		  
		  System.out.println("--------------------------------"); 
		  startIndex += groupCount;
		  
		  } while (orderLineChunkVO.getExistMoreOrderLines());
		 */
	
		
		
		
		/*
		  //Prueba ModifyOrder de PurchaseFacade ++++++++++++++++++
		  Calendar fecha = Calendar.getInstance();
		  fecha.set(2010, 9-1, 22);
		
		  OrderVO orderVO = new OrderVO(new Long(10), new Long(3), "juancito", 70, 7.7,
				2.2,  fecha, Calendar.getInstance()); 
		  
		  purchaseFacade.modifyOrder(orderVO);
		*/
		
		
		 /*
		 //Prueba deleteOrder de PurchaseFacade +++++++++++++++++*
		  
		  purchaseFacade.deleteOrder(new Long(3), new Long(2));
		
		  */
		
		
		 /****************************************
		 * ORDER LINE
		 ****************************************/
		
		
		 /*
		 //Prueba CreateOrderLine de PurchaseFacade ++++++++++++++++++
		
		  OrderLineVO orderLineVO = new OrderLineVO(new Long(2), new Long(9), new Long(6), new Long(5),
				  new Long(3), 23, 5.5); 
		  
		  purchaseFacade.createOrderLine(orderLineVO);
		 */
		
		
		 /*
		  //Prueba FindOrderLineById de PurchaseFacade ++++++++++++++++++
		  
		  OrderLineVO orderLineVO = purchaseFacade
		  		.findOrderLineById(new Long(3),new Long(2), new Long(2));
		  
		  System.out.println(orderLineVO);
		 */
		 
		  
		
		/*
		  //Prueba ModifyOrderLine de PurchaseFacade ++++++++++++++++++

		  OrderLineVO orderLineVO = new OrderLineVO(new Long(6), new Long(9), 
				  new Long(6), new Long(5), new Long(1), 44, 6.6);  
		  
		  purchaseFacade.modifyOrderLine(orderLineVO);
		*/
		
		
		 /*
		 //Prueba deleteOrderLine de PurchaseFacade +++++++++++++++++*
		  
		  purchaseFacade.deleteOrderLine(new Long(5), new Long(4), new Long(3));
		 */
		  

		
		/* SQLOrderLineDAO */
		
		/*
		  //Prueba FindOrderLinesByOrder de SQLOrderLineDAO +++++++++++++++++++++++
		  
		  Connection connection = null;
	      Statement statement = null;
	    		
	  	  SimpleDataSource dataSource = new SimpleDataSource();    
	    	
	  	  connection = dataSource.getConnection();
		  
		  
		  List<OrderLineVO> orderLineVOs;
		  
		  SQLOrderLineDAO orderLineDAO = SQLOrderLineDAOFactory.getDAO();
		  
		  
		  
		  List<OrderLineVO> orderLines =
            orderLineDAO.findByOrder(connection, new Long(22),
            new Long(20), 1, Integer.MAX_VALUE);
		  
		  
		  for (OrderLineVO orderLine : orderLines) {
			    System.out.println(orderLine.getnLinea());
		  }
		*/ 
		
		
		
	} // main
} // class